﻿using Compass.Wasm.Shared.Wms;

namespace Compass.Maui.Services.Cargoes;

public interface ICargoService : IBaseService<CargoDto>
{
    Task<List<CargoDto>> GetMauiAllWithInventoryAsync(int skip, int take, string? search = null);
    Task<List<CargoDto>> GetMauiAllByAreaWithInventoryAsync(Warehouse_e warehouse, Area_e area, string ranks, string? search = null);
}
public class CargoService:BaseService<CargoDto>,ICargoService
{
    private readonly IHttpRestClient _client;
    private const string ServiceName = "Cargo";
    public CargoService(IHttpRestClient client) : base(client, ServiceName)
    {
        _client = client;
    }

    public async Task<List<CargoDto>> GetMauiAllWithInventoryAsync(int skip, int take, string? search = null)
    {
        var strSearch = string.IsNullOrEmpty(search) ? "" : $"&search={search}";
        var request = new BaseRequest
        {
            Method = Method.Get,
            Route = $"{ServiceName}/Maui/All?skip={skip}&take={take}{strSearch}"
        };
        var response = await _client.ExecuteAsync<List<CargoDto>>(request);
        return response.Status ? response.Result : new List<CargoDto>();
    }

    public async Task<List<CargoDto>> GetMauiAllByAreaWithInventoryAsync(Warehouse_e warehouse, Area_e area, string ranks, string? search = null)
    {
        var strSearch = string.IsNullOrEmpty(search) ? "" : $"&search={search}";
        var request = new BaseRequest
        {
            Method = Method.Get,
            Route = $"{ServiceName}/Maui/Area?warehouse={warehouse}&area={area}&ranks={ranks}{strSearch}"
        };
        var response = await _client.ExecuteAsync<List<CargoDto>>(request);
        //返回true，但是结果是空的
        return response.Status ? response.Result : new List<CargoDto>();
    }
}